import App from "./index.vue";
import Vue from "vue";
let appInstance;
/**@description 安装 */
function install() {
  const app = document.getElementById("app").__vue__.$root;

  // 创还能辅助应用
  const dom = document.createElement("div");
  document.body.appendChild(dom);
  appInstance = new Vue({
    el: dom,
    render: (h) =>
      h(App, {
        props: {
          app, // 保证包含vue的应用
        },
        on: {
          // 关闭函数
          close() {
            handler();
          },
        },
      }),
  });
}
/**@description  卸载 */
function uninstall() {
  appInstance.$destroy();
  appInstance.$el.remove();
}

let flag = true;
export default function handler() {
  flag ? install() : uninstall();
  flag = !flag;
}
